package com.uwlaser.modules.system.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.modules.system.service.SysLogsPlantService;
import com.uwlaser.modules.system.service.dto.SysLogsPlantDto;
import com.uwlaser.modules.system.service.dto.SysLogsPlantQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
* @author liuzhihui
* @date 2022-04-04
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "接口日志(中控)管理")
@RequestMapping("/api/sysLogsPlant")
public class SysLogsPlantController {

    private final SysLogsPlantService sysLogsPlantService;

    @GetMapping
    @Log("查询接口日志(中控)")
    @ApiOperation("查询接口日志(中控)")
    @PreAuthorize("@el.check('sysLogsPlant:list')")
    public ResponseEntity query(SysLogsPlantQueryParam query, Pageable pageable){
        return new ResponseEntity<>(sysLogsPlantService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增接口日志(中控)")
    @ApiOperation("新增接口日志(中控)")
    @PreAuthorize("@el.check('sysLogsPlant:add')")
    public ResponseEntity create(@Validated @RequestBody SysLogsPlantDto resources){
        return new ResponseEntity<>(sysLogsPlantService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改接口日志(中控)")
    @ApiOperation("修改接口日志(中控)")
    @PreAuthorize("@el.check('sysLogsPlant:edit')")
    public ResponseEntity update(@Validated @RequestBody SysLogsPlantDto resources){
        sysLogsPlantService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除接口日志(中控)")
    @ApiOperation("删除接口日志(中控)")
    @PreAuthorize("@el.check('sysLogsPlant:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        sysLogsPlantService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出接口日志(中控)")
    @ApiOperation("导出接口日志(中控)")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sysLogsPlant:list')")
    public void download(HttpServletResponse response, SysLogsPlantQueryParam query) throws IOException {
        sysLogsPlantService.download(sysLogsPlantService.queryAll(query), response);
    }*/

}
